package com.xwj.exception.unified.exception.base;

import com.xwj.exception.unified.asserts.ExceptionResponse;
import io.swagger.models.auth.In;
import lombok.Getter;

/**
 * 基础自定义异常，继承自 RuntimeException
 */
@Getter
public class BaseException extends RuntimeException {
    // 错误码
    protected String code;
    // HTTP 状态码
    protected Integer http;

    /**
     * 构造函数
     * @param code 异常编码
     * @param http HTTP 状态码
     * @param msg 异常描述
     */
    private BaseException(String code, Integer http, String msg) {
        super(msg);
        this.code = code;
        this.http = http;
    }

    /**
     * 构造函数
     * @param code 异常编码
     * @param http HTTP 状态码
     * @param msg 异常描述
     * @param cause 异常
     */
    private BaseException(String code, Integer http, String msg, Throwable cause) {
        super(msg, cause);
        this.code = code;
        this.http = http;
    }

    /**
     * 构造函数
     * @param resp
     */
    public BaseException(ExceptionResponse resp) {
        this(resp.getCode(), resp.getHttp(), resp.getMessage());
    }

    /**
     * 构造函数
     * @param resp
     * @param message
     */
    public BaseException(ExceptionResponse resp, String message) {
        this(resp.getCode(), resp.getHttp(), message);
    }

    /**
     * 构造函数
     * @param resp
     * @param message
     * @param cause
     */
    public BaseException(ExceptionResponse resp, String message, Throwable cause) {
        this(resp.getCode(), resp.getHttp(), message, cause);
    }

}
